package ExerChapter15Collection_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class list_ {
    @SuppressWarnings({ "all" })
    public static void main(String[] args) {
        List list = new ArrayList<>();
        list.add(new Dog("A", 1));
        list.add(new Dog("B", 2));
        list.add(new Dog("C", 3));

        Dog foo = new Dog("D", 4);
        list.add(foo);

        Iterator it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next().toString());
        }

        // 这里不能用List list2 = list.subList(2, 4);因为返回的是原列表视图
        List list2 = new ArrayList<>(list.subList(2, 4));
        System.out.println(list2);

        list.add(2, foo);

        // list.addAll(list2);
        list.addAll(list2);
        System.out.println(list);
    }
}

class Dog {
    String name;
    double age;

    public Dog(String name, double age) {
        this.name = name;
        this.age = age;
    }

    public Dog() {
    }

    @Override
    public String toString() {
        return "Dog [name=" + name + ", age=" + age + "]";
    }

}